package cn.itcast.springboot.controller;

import cn.itcast.springboot.config.Person;
import cn.itcast.springboot.pojo.User;
import cn.itcast.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;

@RestController
public class HelloController {

    @Autowired
    private DataSource dataSource;

    @Autowired
    private Person person;

    @Autowired
    private UserService userService;

    @GetMapping("/hello")
    public String hello() {
        System.out.println(person);
        return "hello springboot!";
    }

    /*org.springframework.jdbc.CannotGetJdbcConnectionException:
    Failed to obtain JDBC Connection; nested exception is java.sql.SQLException:
    The server time zone value 'ÖÐ¹ú±ê×¼Ê±¼ä' is unrecognized or represents more than one time zone.
    You must configure either the server or JDBC driver (via the serverTimezone configuration property)
    to use a more specifc time zone value if you want to utilize time zone support*/
    @GetMapping("/hello/{id}")
    public User hello(@PathVariable Long id) {

        return userService.queryUserById(id);
    }
}
